package com.hx.springboot1.controller;

import com.github.pagehelper.PageInfo;
import com.hx.springboot1.service.impl.UserServiceImpl;
import com.hx.springboot1.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Author: hx
 * Date: 2021-05-15 21/05
 * Description: Nothing else
 */
@Controller
public class UserController {

    @Autowired
    UserServiceImpl userServiceImpl;

    @RequestMapping("/selectUser")
    public String selectUser(String searchName, Integer pageNum, Integer pageSize,Model model){
        PageInfo pageInfo = userServiceImpl.selectAllUser(searchName, pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "manage/accountList";
    }
    @GetMapping("/userState/{s}/{id}")
    public String updateUserState(@PathVariable(value = "s") String userState,@PathVariable(value = "id") String userId, Model model){
        userServiceImpl.updateUserState(userState,userId);
        String s = this.selectUser("", 1, 10, model);
        return s;
    }

    @GetMapping("/resetPwd")
    @ResponseBody
    public ResultMsg reset(Integer userId){
        return userServiceImpl.resetPwd(userId);
    }
    @PostMapping("/updatePWD")
    @ResponseBody
    public ResultMsg updatePWD(Integer userId,String newPWD){
        return userServiceImpl.updatePWD(userId,newPWD);
    }
}
